<template>
  <div :id="id" :style="{ height:height,width:width}"></div>
</template>

<script>
export default {
  name: "pie",
  props: {
    id: {
      type: String,
      default: 'pie'
    },
    width: {
      type: String,
      default: "100%"
    },
    height: {
      type: String,
      default: "300px"
    },
    data:{
      type: Array,
      default: () => [{value: 1, name: '搜索引擎'},
        {value: 1, name: '直接访问'},
        {value: 1, name: '邮件营销'},
        {value: 1, name: '联盟广告'},
        {value: 1, name: '视频广告'}]
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart();
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    refreshData(data){
      var option = this.chart.getOption();
      option.series[0].data = data;
      this.chart.setOption(option);
    },
    initChart() {
      let echarts = require('echarts');
      this.chart = echarts.init(document.getElementById(this.id));
      const option = {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left',
          textStyle:{
            color: '#fff',
            // fontWeight: '400',
            // 字体系列
            // fontFamily: 'Source Han Sans CN',
            // 字体大小
            fontSize: 12,
          }
        },
        grid: {
          right: 0,
          bottom: 0,
        },
        series: [
          {
            name: '评论聚类结果',
            type: 'pie',
            radius: '50%',
            data: this.data,
            center: ['70%','50%'],
            label: {
              normal: {
                // position: 'inner',
                // show : false
                itemStyle: {
                  shadowBlur: 0,
                  shadowOffsetX: 0,
                  shadowOffsetY: 0,
                  shadowColor: 'rgba(0, 0, 0，0)'
                },
                textStyle: {            // 提示文字的样式
                  color: 'white',
                  fontSize: 14
                }
              }
            },
            // emphasis: {
            //   itemStyle:{
            //     shadowBlur: 10,
            //     shadowOffsetX: 0,
            //     shadowColor: 'rgba(30, 144, 255，1)'
            //   }
            // }
          }
        ]
      };
      this.chart.setOption(option);
    }
  }
}
</script>

<style scoped>

</style>
